/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package database_client;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 *
 * @author suzunghia
 */
public class LogInScreen extends JDialog implements ActionListener{
    JTextField user;
    JPasswordField pass;
    JTextField IP;
    JButton connect;
    MainFrame main;
    public LogInScreen()
    {
        
    }
    public void ShowGUI(MainFrame parent)
    {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        main = parent;
        JPanel pIp = new JPanel();
        pIp.setLayout(new BoxLayout(pIp, BoxLayout.X_AXIS));
        JPanel pUser = new JPanel();
        pUser.setLayout(new BoxLayout(pUser, BoxLayout.X_AXIS));
        JPanel pPass = new JPanel();
        pPass.setLayout(new BoxLayout(pPass, BoxLayout.X_AXIS));
        JLabel Lb_ip = new JLabel("   IP Address: ");
        Lb_ip.setPreferredSize(new Dimension(100, 30));
        IP = new JTextField();
        IP.setPreferredSize(new Dimension(100, 30));
        JLabel Lb_user = new JLabel("   User name: ");
        Lb_user.setPreferredSize(new Dimension(100, 30));
        user = new JTextField();
        user.setPreferredSize(new Dimension(100, 30));
        JLabel Lb_pass = new JLabel("   Password: ");
        Lb_pass.setPreferredSize(new Dimension(100, 30));
        pass = new JPasswordField();
        pass.setPreferredSize(new Dimension(100, 30));
        connect = new JButton("Connect");
        connect.addActionListener(this);
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
        pIp.add(Lb_ip);
        pIp.add(IP);
        pUser.add(Lb_user);
        pUser.add(user);
        pPass.add(Lb_pass);
        pPass.add(pass);
        p.add(pIp);
        p.add(pUser);
        p.add(pPass);

        JPanel button = new JPanel(new GridLayout(1, 1));
        button.add(connect);



        this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.X_AXIS));
        add(p);
        add(button);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setSize(400, 120);
        this.setLocation((parent.getWidth()/2 - this.getWidth()/3), (parent.getHeight() - this.getHeight())/2);
        pack();
        this.setModal(true);
        setVisible(true);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource() == connect)
        {
            main.user = user.getText();
            main.pass = pass.getText();
            main.ip = IP.getText();
            this.dispose();
        }
    }
    
}
